﻿using Entity.BaseInfo.DTO.Warehouse;
using Entity.BaseInfo.View.Warehouse;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Service.BaseInfo;

namespace AnQinManagermentBackendAPI.Controller.BaseInfo
{
    /// <summary>
    /// 仓库表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class WarehouseController : ControllerBase
    {
        /**
         * 仓库业务接口
         */
        private readonly WarehouseService _warehouseService;

        /**
         * 构造函数注入
         */
        public WarehouseController(WarehouseService warehouseService)
        {
            _warehouseService = warehouseService;
        }

        /// <summary>
        /// 获取仓库列表
        /// </summary>
        /// <param name="warehouseSearchDTO"></param>
        [HttpGet]
        [ProducesResponseType(typeof(WarehouseView), 200)]
        public async Task<IActionResult> GetWarehouseList([FromQuery] WarehouseSearchDTO warehouseSearchDTO)
        {
            var response = await _warehouseService.GetWarehouseList(warehouseSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增仓库
        /// </summary>
        /// <param name="warehouseAddDTO"></param>
        [HttpPost]
        public async Task<IActionResult> AddWarehouse([FromBody] WarehouseAddDTO warehouseAddDTO)
        {
            var response = await _warehouseService.AddWarehouse(warehouseAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 更新仓库
        /// </summary>
        /// <param name="warehouseUpdateDTO"></param>
        [HttpPut]
        public async Task<IActionResult> PutWarehouse([FromBody] WarehouseUpdateDTO warehouseUpdateDTO)
        {
            var response = await _warehouseService.PutWarehouse(warehouseUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除仓库
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteWarehouse([FromQuery] string Id)
        {
            var response = await _warehouseService.DeleteWarehouse(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 获取仓库下拉列表
        /// </summary>
        /// <param name="warehouseSelectSearchDTO"></param>
        [HttpGet("Select")]
        [ProducesResponseType(typeof(WarehouseSelectView), 200)]
        public async Task<IActionResult> GetDepartmentList([FromQuery] WarehouseSelectSearchDTO warehouseSelectSearchDTO)
        {
            var response = await _warehouseService.GetWarehouseSelectList(warehouseSelectSearchDTO);
            return StatusCode(response.Status, response);
        }
    }
}
